<template>
  <div id="AsnDetail">
    <div class="detail">
      <v-navMenu
          :detailNav="detailNav"
          :menuData="menuData"
          @setMentActive="setMentActive"
      ></v-navMenu>
      <keep-alive>
        <component 
            :inputData="detailData"
            :is="currentComponent"
        ></component>
      </keep-alive>
    </div>
  </div>

</template>

<script>
import detail from "commons/Detail";
import navMenu from "commons/NavMenu";
import baseMixin from "@/mixins/BaseMixin";

export default {
  name: "Detail",
  mixins: [baseMixin],
  data() {
    return {
      flag: true,
      newFlag: false,
      menuData: [
        { label: this.$t('in.asn'), index: "1" },
        { label: this.$t('config.general'), index: "2" },
        { label: this.$t('in.shipAddress'), index: "3" },
        { label: this.$t('config.carrier'), index: "4" },
        { label: this.$t('in.loading'), index: "5" },
        { label: this.$t('in.receiptDetails'), index: "6" }
      ],
      selectData: {},
      detailData: {},
      detailNav: "1",
      componentConfig: [
        {
          name: "asnDetails",
          label: this.$t('in.asn'),
          component: () => import("./page/AsnDetails.vue")
        },
        {
          name: "RoutineDetails",
          label: this.$t('config.general'),
          component: () => import("./page/RoutineDetails.vue")
        },
        {
          name: "ShipAddressDetails",
          label: this.$t('in.shipAddress'),
          component: () => import("./page/ShipAddressDetails.vue")
        },
        {
          name: "CarrierDetails",
          label: this.$t('config.carrier'),
          component: () => import("./page/CarrierDetails.vue")
        },
        {
          name: "LoadingDetails",
          label: this.$t('in.loading'),
          component: () => import("./page/LoadingDetails.vue")
        },
        {
          name: "ReceiptDetails",
          label: this.$t('in.receiptDetails'),
          component: () => import("./page/ReceiptDetails.vue")
        }
      ]
    };
  },
  computed: {
    currentComponent() {
      return this.componentConfig[this.detailNav - 1].component;
    }
  },
  methods: {
    setMentActive(key) {
      this.detailNav = key;
    },
    async getData() {
      try {
        let res = await this.$api.get(`/asn/detailed/${this.selectData.receiptkey}`);
        
          this.$nextTick(() => {
            this.detailData = {
              ...this.detailData,
              ...res.bean
            };

            if (!this.detailData.temperature) {
              this.$set(this.detailData, "temperature", null);
            }

          });
      } catch (e) {
        this.$message.error(e);
      }
    }
  },
  mounted() {

    // let newFlag = this.$store.state.newFlag;
    // //判断是否事新建
    // if (newFlag) {
    //   this.newFlag = true;

    //   for (let i in this.detailData) {
    //     this.detailData[i] = "";
    //   }
    //   this.detailData = {
    //     receiptkey: this.$store.state.routeId,
    //     storerkey: "",
    //     status: "0",
    //     grossweight: "0",
    //     totalvolume: "0",
    //     overageoveridepercent: "1",
    //     type: "1",
    //     allowautoreceipt: "0",
    //     notes: " ",
    //     temperature: null,
    //     carrierphone: null
    //   };
    // }
    // if (Object.keys(this.$store.state.skip).length !== 0) {
    //   let data = this.$store.state.skip;
    //   this.detailData = data.detail;
    //   this.selectData = data.routeData;
    //   this.detailNav = data.detailNav;
    //   this.getData();
    // } else {
    //   this.selectData = this.$store.state.routeData;
    //   this.getData();
    // }
    const query = this.$route.query;
    if(query.newFlag){
      this.newFlag = true;
      let numberType = 11702;
      this.$api.get("/sysNumberRule/getSysNumberByType/"+numberType).then(res => {
        
          this.detailData = {
            receiptkey: res.data.data,
            storerkey: "",
            status: "0",
            grossweight: "0",
            totalvolume: "0",
            overageoveridepercent: "1",
            type: "1",
            allowautoreceipt: "0",
            notes: " ",
            temperature: null,
            carrierphone: null
          };
        
      })
    }else{
      this.detailData = query;
      this.selectData = query;
      this.getData();
    }
  },
  components: {
    "v-detail": detail,
    "v-navMenu": navMenu
  }

};
</script>

<style scoped>
</style>
